<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	$item=$this->plugin_setting('sale_offer');
	$item['title']=$item['title']?:'今日特价商品';
	$item['desc']=$item['desc']?:'今日特价，一周机会只有一次哦！一人只能购买一份哦！';
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'set',
		'desc'=>'今日特价设置',
		'edit'=>array(
			array('type'=>'switch','name'=>'isopen','title'=>'是否开启','help'=>'默认关闭，开启后，首页会弹窗提示今日特价，属于今日特价的商品，会显示今日特价！'),
			array('type'=>'string','name'=>'title','title'=>'弹窗标题','help'=>'特价弹窗标题，建议不要大于10个字'),
			array('type'=>'string','name'=>'desc','title'=>'弹窗描述','help'=>'特价弹窗描述，建议不要大于20个字'),
			array('type'=>'string','name'=>'discount','title'=>'折扣力度','help'=>'特价折扣必须是整数,且大于10小于100'),
			array('type'=>'string','name'=>'maxnum','title'=>'最大购买量','help'=>'特价购买量必须是整数'),
			array('type'=>'radio','name'=>'weeks','title'=>'星期','options'=>'weeks','help'=>''),
			array('type'=>'choose_many','name'=>'goods_ids0','title'=>'星期天参与的商品','show'=>array('weeks'=>0),'action'=>'/goods.get_goods/many/','choose_title'=>'选择参与的商品'),
			array('type'=>'choose_many','name'=>'goods_ids1','title'=>'星期一参与的商品','show'=>array('weeks'=>1),'action'=>'/goods.get_goods/many/','choose_title'=>'选择参与的商品'),
			array('type'=>'choose_many','name'=>'goods_ids2','title'=>'星期二参与的商品','show'=>array('weeks'=>2),'action'=>'/goods.get_goods/many/','choose_title'=>'选择参与的商品'),
			array('type'=>'choose_many','name'=>'goods_ids3','title'=>'星期三参与的商品','show'=>array('weeks'=>3),'action'=>'/goods.get_goods/many/','choose_title'=>'选择参与的商品'),
			array('type'=>'choose_many','name'=>'goods_ids4','title'=>'星期四参与的商品','show'=>array('weeks'=>4),'action'=>'/goods.get_goods/many/','choose_title'=>'选择参与的商品'),
			array('type'=>'choose_many','name'=>'goods_ids5','title'=>'星期五参与的商品','show'=>array('weeks'=>5),'action'=>'/goods.get_goods/many/','choose_title'=>'选择参与的商品'),
			array('type'=>'choose_many','name'=>'goods_ids6','title'=>'星期六参与的商品','show'=>array('weeks'=>6),'action'=>'/goods.get_goods/many/','choose_title'=>'选择参与的商品'),
		)
	);
	$return['weeks']=array('0'=>'星期天','1'=>'星期一','2'=>'星期二','3'=>'星期三','4'=>'星期四','5'=>'星期五','6'=>'星期六');
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='set'){
	$post=get_postdata();
	$post['discount']=intval($post['discount']);
	if(!is_int($post['discount']) || $post['discount']>100 || $post['discount']<10){
			exi('折扣必须是整数,且大于10小于100','error');	
	}
	$post['maxnum']=intval($post['maxnum']);
	if(!is_int($post['maxnum'])){
			exi('最大购买量必须是整数','error');	
	}
	$this->plugin_setting('sale_offer',$post);
	exi('设置成功');
}